﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Evpo.ContactData.Common;
using System.Data.SqlClient;

namespace Evpo.ContactData.Data
{
    public class Connection : IConnection
    {
        public Connection(string connString)
        {
            SqlConn = new SqlConnection(connString);
        }

        public SqlConnection SqlConn
        {
            get;
            private set;
        }

        public void Open()
        {
            SqlConn.Open();
        }

        public bool IsOpen
        {
            get { return (SqlConn.State == System.Data.ConnectionState.Open); }
        }

        public void Close()
        {
            SqlConn.Close();
        }

        public void AssertConnectionIsOpen()
        {
            if (!IsOpen)
                throw new ApplicationException("Connection must be open");
        }
    }
}
